package fun.stgoder.test1;

import java.util.ArrayList;
import java.util.List;

public class TestVolatile {

    private static List<Integer> list = new ArrayList<>();

    public static void main(String[] args) {


        new Thread(() -> {
            for (int i = 0; i < 20; i++) {
                list.add(i);
                System.out.println("add " + i);
                TestUtil.sleepSeconds(1);
            }
        }).start();

        new Thread(() -> {
            while (true) {
                if (list.size() == 5) {
                    System.out.println("break");
                    break;
                }

                TestUtil.sleepSeconds(1);
            }
        }).start();
    }
}
